package com.neulogistics.contrib.procuredcenter.api;

import com.blackto.lib.eventbus.abstraction.IEventBus;
import com.blackto.lib.eventbus.abstraction.IIntegrationEventHandler;

import com.neulogistics.contrib.procuredcenter.api.application.integrationevent.subscribe.CenterReturnOutboundIntegrationEvent;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

@Component
public class Initializer implements ApplicationRunner {
    private final IEventBus eventBus;

    @Resource
    IIntegrationEventHandler<CenterReturnOutboundIntegrationEvent> centerReturnOutboundIntegrationEventHandler;

    public Initializer(IEventBus eventBus) {
        this.eventBus = eventBus;
    }


    @Override
    public void run(ApplicationArguments args) throws Exception {
        // 在此订阅本项目需要接受的集成事件，并指定handler
        eventBus.subscribe(CenterReturnOutboundIntegrationEvent.class, centerReturnOutboundIntegrationEventHandler.getClass());
    }
}
